<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: EVTGEN       (Event Generator)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__evtgen.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">API Reference</a>  </div>
  <div class="headertitle">
<div class="title">EVTGEN (Event Generator)</div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>This driver provides API functions to configure and use the Event Generator. </p>
<p>The functions and other declarations used in this driver are in cy_evtgen.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.</p>
<h1><a class="anchor" id="group_evtgen_glossary"></a>
Glossary</h1>
<ul>
<li>Structure or Comparator Structure - is the main instance of the Event Generator that set of two comparators.</li>
<li>Comparator - it is a sub-module of Structures for saving value to compare.</li>
</ul>
<h1><a class="anchor" id="group_evtgen_solution"></a>
EVTGEN Solution</h1>
<p>The Event Generator (EVTGEN) implements event generation - in Active mode, for interrupts and triggers and in Deep Sleep mode only for interrupts. The Active functionality interrupt is connected to the CPU interrupt controller. Active mode triggered events can be used to trigger a specific device functionality mode (for example, execution of an interrupt handler, a SAR ADC conversion, and so on) in Active power mode. The Deep Sleep functionality interrupts can be used to wake up the CPU from the Deep Sleep power mode. The event generator includes a single counter and a maximum of 16 comparator structures for each Active and Deep Sleep mode. EVTGEN reduces CPU involvement and thus overall power consumption and jitters. </p><div class="image">
<img src="evtgen_architecture.png" alt="evtgen_architecture.png"/>
</div>
<p>EVTGEN consists of two blocks: Active and Deep Sleep mode blocks. There are 16 comparator structures and one 32-bit counter for each of the modes which increment with each cycle CLK_REF. Each comparator structure has an Active and a Deep Sleep comparator. A comparator compares a programmed comparator value with the current counter value. When the counter value "passes" (equal) a comparator value, a comparator output is activated. </p><div class="image">
<img src="evtgen_clock_structure.png" alt="evtgen_clock_structure.png"/>
</div>
<p> The Event Generator implements synchronization between the Active counter and Deep Sleep counter through ratio control. The ratio value shows the number of clk_ref_div periods in one clk_lf periods. Event Generator uses Ratio value to synchronize active counter and Deep Sleep counter with hardware automatically.</p>
<h1><a class="anchor" id="group_evtgen_configuration"></a>
Configuration Considerations</h1>
<p>The EVTGEN driver configuration can be divided into a number of sequential steps:</p><ul>
<li><a class="el" href="group__group__evtgen.html#group_scb_evtgen_config">Configure EVTGEN</a></li>
<li><a class="el" href="group__group__evtgen.html#group_scb_evtgen_clock">Enable Clock Path</a></li>
<li><a class="el" href="group__group__evtgen.html#group_scb_evtgen_intr">Configure Interrupt</a></li>
<li><a class="el" href="group__group__evtgen.html#group_scb_evtgen_enable">Enable EVTGEN</a></li>
<li><a class="el" href="group__group__evtgen.html#group_scb_evtgen_comp_struct_config">Configure Comparator Structure</a></li>
</ul>
<dl class="section note"><dt>Note</dt><dd>The EVTGEN driver is built on top of the EVTGEN hardware block. The EVTGEN0 instance is used as an example for all code snippets. Modify the code to match your design.</dd></dl>
<h2><a class="anchor" id="group_scb_evtgen_config"></a>
Configure EVTGEN</h2>
<p>To set up the EVTGEN driver, provide the configuration parameters in the <a class="el" href="structcy__stc__evtgen__config__t.html">cy_stc_evtgen_config_t</a> structure. To initialize the driver, call the <a class="el" href="group__group__evtgen__functions.html#gab92728e8051ea3f8a8fd97a22510046d">Cy_EvtGen_Init</a> function providing a pointer to the populated <a class="el" href="structcy__stc__evtgen__config__t.html">cy_stc_evtgen_config_t</a> structure.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="comment">/* Populate the configuration structure */</span></div><div class="line"><a class="code" href="structcy__stc__evtgen__config__t.html">cy_stc_evtgen_config_t</a> configEvtGen = </div><div class="line">{</div><div class="line">    .<a class="code" href="structcy__stc__evtgen__config__t.html#a603866d3c5799f3198b38891312e5ada">frequencyRef</a> = 8000000u,</div><div class="line">    .frequencyLf = 32800u,</div><div class="line">    .frequencyTick = 1000000u,</div><div class="line">    .ratioControlMode = <a class="code" href="group__group__evtgen__enums.html#gga4461ea1a58eded2d77ab335791b7bc30a3a68493060dd7beee2d50cfd53d35eb2">CY_EVTGEN_RATIO_CONTROL_SW</a>,</div><div class="line">    .ratioValueDynamicMode = <a class="code" href="group__group__evtgen__enums.html#ggae3ae3b797ed9262472524c9a917b3ce6aa379d7c1be4d8b61ef8f4a2ba7b9bc74">CY_EVTGEN_RATIO_DYNAMIC_MODE0</a>,</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">/* Configure EVTGEN to operate */</span></div><div class="line">(void) <a class="code" href="group__group__evtgen__functions.html#gab92728e8051ea3f8a8fd97a22510046d">Cy_EvtGen_Init</a>(EVTGEN0, &amp;configEvtGen);</div></div><!-- fragment --><h2><a class="anchor" id="group_scb_evtgen_clock"></a>
Enable Clock Path</h2>
<p>A clock source must be connected to the EVTGEN block to control time. Enable High Frequency clock. Use the <a class="el" href="group__group__sysclk.html">SysClk (System Clock)</a> driver API to do.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3_ENABLED 1UL</span></div><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3_DIVIDER CY_SYSCLK_CLKHF_NO_DIVIDE</span></div><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3 3UL</span></div><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3_FREQ_MHZ 8UL</span></div><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3_CLKPATH CY_SYSCLK_CLKHF_IN_CLKPATH6</span></div><div class="line"><span class="preprocessor">#define CY_CFG_SYSCLK_CLKHF3_CLKPATH_NUM 6UL</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">/* Connect the assigned Clock Path to be a clock source for EVTGEN */</span></div><div class="line">    <a class="code" href="group__group__sysclk__clk__hf__funcs.html#ga2d39c7e5111f9ba0738f032a98b4593e">Cy_SysClk_ClkHfSetSource</a>(CY_CFG_SYSCLK_CLKHF3, CY_CFG_SYSCLK_CLKHF3_CLKPATH);</div><div class="line">    <a class="code" href="group__group__sysclk__clk__hf__funcs.html#ga66c6e94768403ab318f2aa321b4c1e50">Cy_SysClk_ClkHfSetDivider</a>(CY_CFG_SYSCLK_CLKHF3, <a class="code" href="group__group__sysclk__clk__hf__enums.html#ggadfbf0caf87af7cd757648124fb17d1d4a996f9d53d3d78eda51e71dd65b1990c0">CY_SYSCLK_CLKHF_NO_DIVIDE</a>);</div><div class="line">    <a class="code" href="group__group__sysclk__clk__hf__funcs.html#gace8a5255f8579c17f4062dccb3ff3694">Cy_SysClk_ClkHfDirectSel</a>(CY_CFG_SYSCLK_CLKHF3, <span class="keyword">false</span>);</div><div class="line">    <a class="code" href="group__group__sysclk__clk__hf__funcs.html#gaf3041fc8333478cc7c8d869d2a535d71">Cy_SysClk_ClkHfEnable</a>(CY_CFG_SYSCLK_CLKHF3);</div></div><!-- fragment --><h2><a class="anchor" id="group_scb_evtgen_comp_struct_config"></a>
Configure Comparator Structure</h2>
<p>To set up the Comparator Structure of the EVTGEN driver, provide the configuration parameters in the <a class="el" href="structcy__stc__evtgen__struct__config__t.html">cy_stc_evtgen_struct_config_t</a> structure. To initialize the Comparator Structure, call the <a class="el" href="group__group__evtgen__functions.html#ga423ba1577ae9242fa0997a6f72d86317">Cy_EvtGen_InitStruct</a> function providing a pointer to the populated <a class="el" href="structcy__stc__evtgen__struct__config__t.html">cy_stc_evtgen_struct_config_t</a> structure.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="comment">/* Populate configuration structure */</span></div><div class="line"><a class="code" href="structcy__stc__evtgen__struct__config__t.html">cy_stc_evtgen_struct_config_t</a> evtgen_configStruct0 =</div><div class="line">{</div><div class="line">    .<a class="code" href="structcy__stc__evtgen__struct__config__t.html#a10c261460e72411b4bfcb115db8d530b">functionalitySelection</a> = CY_EVTGEN_ACTIVE_FUNCTIONALITY,</div><div class="line">    .triggerOutEdge = CY_EVTGEN_EDGE_SENSITIVE,</div><div class="line">    .valueActiveComparator = 500000u,</div><div class="line">    .valueDeepSleepComparator = 80000u</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">/* Configure Comparator Structure to operate */</span></div><div class="line">(void) <a class="code" href="group__group__evtgen__functions.html#ga423ba1577ae9242fa0997a6f72d86317">Cy_EvtGen_InitStruct</a>(EVTGEN0, 0u, &amp;evtgen_configStruct0);</div></div><!-- fragment --><h2><a class="anchor" id="group_scb_evtgen_intr"></a>
Configure Interrupt</h2>
<p>The interrupt is the main operation of EVTGEN. Use it to configure an interrupt and create the interrupt handle for the selected EVTGEN instance. Also, enable this interrupt in the NVIC.</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> EVTGEN_Isr(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span>(<a class="code" href="group__group__evtgen__functions.html#gaa042e4327ef588d9007a0ea99109b893">Cy_EvtGen_GetStructInterrupt</a>(EVTGEN0, 0u))</div><div class="line">    {</div><div class="line">        <a class="code" href="group__group__evtgen__functions.html#ga618547de75dcc000dccf4db88aeb3394">Cy_EvtGen_ClearStructInterrupt</a>(EVTGEN0, 0u);</div><div class="line">        <a class="code" href="group__group__evtgen__functions.html#ga5e0f0407c43af8d2293d9a6545932c25">Cy_EvtGen_UpdateActiveCompValue</a>(EVTGEN0, 0u, 500000u);</div><div class="line">        <span class="comment">/* </span></div><div class="line"><span class="comment">            User&#39;s ISR for Comparator Structure 0</span></div><div class="line"><span class="comment">        */</span></div><div class="line">    }</div><div class="line">}</div></div><!-- fragment --><div class="fragment"><div class="line"><span class="keywordtype">void</span> EVTGEN_Cfg_Isr(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line"><span class="comment">/* Assign the EVTGEN interrupt number and priority */</span></div><div class="line"><span class="preprocessor">#define EVTGEN_INTR_NUM        (((NvicMux3_IRQn &lt;&lt; CY_SYSINT_INTRSRC_MUXIRQ_SHIFT) | evtgen_0_interrupt_IRQn))</span></div><div class="line"><span class="preprocessor">#define EVTGEN_INTR_PRIORITY   (7u)</span></div><div class="line"></div><div class="line"><span class="comment">/* Populate configuration structure (code specific for CM4) */</span></div><div class="line"><span class="keyword">const</span> <a class="code" href="structcy__stc__sysint__t.html">cy_stc_sysint_t</a> evtgenIntrConfig =</div><div class="line">{</div><div class="line">    .<a class="code" href="structcy__stc__sysint__t.html#a204a8f07adf056c8d3dd818136da853f">intrSrc</a>      = EVTGEN_INTR_NUM,</div><div class="line">    .intrPriority = EVTGEN_INTR_PRIORITY,</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">/* Hook the interrupt service routine and enable the interrupt */</span></div><div class="line">(void) <a class="code" href="group__group__sysint__functions.html#gab2ff6820a898e9af3f780000054eea5d">Cy_SysInt_Init</a>(&amp;evtgenIntrConfig, &amp;EVTGEN_Isr);</div><div class="line"><a class="code" href="group__group__evtgen__functions.html#gaaceb8c826989cd626c65aa1241fc2a94">Cy_EvtGen_ClearInterrupt</a>(EVTGEN0, 0xFFu); </div><div class="line">NVIC_ClearPendingIRQ(NvicMux3_IRQn); </div><div class="line">NVIC_EnableIRQ((<a class="code" href="group__group__sysint__enums.html#ga7e1129cd8a196f4284d41db3e82ad5c8">IRQn_Type</a>)NvicMux3_IRQn);</div><div class="line"></div><div class="line"><span class="preprocessor">#if (USE_EVTGEN_TRIGGER)</span></div><div class="line">    <a class="code" href="group__group__trigmux__functions.html#ga3671fac144b75c3b3eddc5ab46ae96f6">Cy_TrigMux_Connect</a>(TRIG_IN_MUX_1_EVTGEN_TR_OUT0,</div><div class="line">                       TRIG_OUT_MUX_1_PDMA0_TR_IN16,</div><div class="line">                       0UL,</div><div class="line">                       TRIGGER_TYPE_EDGE);</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line">}</div></div><!-- fragment --><h2><a class="anchor" id="group_scb_evtgen_enable"></a>
Enable EVTGEN</h2>
<p>Finally, enable the EVTGEN operation by calling <a class="el" href="group__group__evtgen__functions.html#ga789985f17a9cfbffb46e4afcd75d14ac">Cy_EvtGen_Enable</a>.</p>
<div class="fragment"><div class="line"><span class="comment">/* Enable EVTGEN to operate */</span></div><div class="line"><a class="code" href="group__group__evtgen__functions.html#ga789985f17a9cfbffb46e4afcd75d14ac">Cy_EvtGen_Enable</a>(EVTGEN0);</div><div class="line"></div><div class="line"><span class="preprocessor">#if (USE_HW_RATIO_CONTROL)</span></div><div class="line">    <span class="keywordflow">while</span>(<a class="code" href="group__group__evtgen__functions.html#gabf1d365805e6466bbe963e3561d0988d">Cy_EvtGen_GetRatioStatus</a>(EVTGEN0) != <span class="keyword">true</span>)</div><div class="line">    {</div><div class="line">        __NOP();</div><div class="line">    }</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="comment">/* Enable global interrupts */</span></div><div class="line">__enable_irq();</div></div><!-- fragment --> <h1><a class="anchor" id="group_evtgen_changelog"></a>
Changelog</h1>
<table class="doxtable">
<tr>
<th>Version</th><th>Changes</th><th>Reason for Change </th></tr>
<tr>
<td>1.0 </td><td>Initial version </td><td></td></tr>
</table>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
API Reference</h2></td></tr>
<tr class="memitem:group__group__evtgen__macros"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__evtgen__macros.html">Macro</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__evtgen__functions"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__evtgen__functions.html">Functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__evtgen__data__structures"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__evtgen__data__structures.html">Data structures</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__evtgen__enums"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__evtgen__enums.html">Enumerated types</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
